$(function() {
	$("#stop").hide();
});

var timmerID;
function start(type){
	$("#start").hide();
	$("#stop").show();
	timmerID = setInterval("monitor("+type+")",7000);  //调取函数，调取频率毫秒
}

function stop(){
	$("#start").show();
	$("#stop").hide();
	window.clearInterval(timmerID);
	timmerID = null;
}

function monitor(type){
	var ajax = new $ax(Feng.ctxPath + "/realtime/monitor/yday/list", function (data) {
		eachHtml(data);
    }, function (data) {
        Feng.error("查询失败!" + data.responseJSON.message + "!");
    });
	ajax.set("gTime",$("#gTime").val());
    ajax.set("zlje",$("#zlje").val());
    ajax.set("mp",$("#mp").val());
    ajax.set("lbcount",$("#lbcount").val());
    ajax.set("wt",$("#wt").val());
    ajax.start();
}

function eachHtml(json){
	var dashboard = "";
	$.each(json.dashboard,function(k1,v1) {
		dashboard += v1.gName + v1.gLastPx +v1.gPxChange + v1.gPxChangeRate;
	});
	$("#dashboard").html(dashboard);

    var dashboardbk = "<font color='red' font size='3'><b>";
    $.each(json.bkqd,function(k1,v1) {
        dashboardbk += v1.gName + "&nbsp;" + v1.gBkQd + "&nbsp;&nbsp;&nbsp;&nbsp;";
    });
    dashboardbk+="</b></font>";
    $("#dashboardbk").html(dashboardbk);

	var dashboardd = "";
	$.each(json.dashboardd,function(k1,v1) {
		dashboardd += v1.context;
	});
	$("#dashboardd").html(dashboardd);
	
	var html = "<div class='row'>";
	$.each(json.fengk,function(k1,v1) {
		if(k1 %3 ==2){
			html += "<div class='row'>";
		}
		html += "<div class='col-sm-4'><div class='ibox float-e-margins'>"
		    +"<div class='ibox-title'>";
		if(v1.zln > 8){
			html += "<b>所属行业:</b><font size='2' color='red'>"+v1.gOwerBk+"</font>&nbsp;&nbsp;<b>代码:"+v1.gScode+"&nbsp;&nbsp;股票名:<b class='blink_red'>"+v1.gName+"</b></br>";
		}else{
			html += "<b>所属行业:</b><font size='2' color='red'>"+v1.gOwerBk+"</font>&nbsp;&nbsp;<b>代码:"+v1.gScode+"&nbsp;&nbsp;股票名:"+v1.gName+"</br>";
		}
		html +="概念属性:"+v1.gConceptBk+""
		    +"</br>分口分析:<font color='red'>"+v1.gReason+"</font>&nbsp;&nbsp;控盘度:"+v1.gJgcydType+"&nbsp;&nbsp;流通市值:"+v1.gZsz+"(亿)</b></div>" +
		    "<div class='ibox-title'>"
		    +"<b>主力净额:</b><font size='2' color='red'>"+v1.gZlje+"</font>&nbsp;&nbsp;<b>主力买入:</b>"+v1.gZlbuy+"&nbsp;&nbsp;<b>主力卖出:"+v1.gZlShell+"</br>"
		    +"<b>最新价:</b>"+v1.gPrice+"&nbsp;&nbsp;涨跌幅(%):"+v1.gRate+"&nbsp;&nbsp;<b>换手率:</b>"+v1.gHsl+"%<b></br>龙头属性:</b><font size='2' color='red'>"+v1.gDis+"</font>&nbsp;&nbsp;<b>连板属性:</b><font size='2' color='red'>"+v1.gLb+"</font></b>&nbsp;&nbsp;<b>涨速:</b>"+v1.gZs+"</b>"+"</b>&nbsp;&nbsp;<b>承接百分比:<font size='2' color='red'>"+v1.zln+"</font></b></br>" +"</b><b>竞价量能:"+v1.ln+"</b></br>"+
		    "</div>"+
		    "<div class='ibox-title'>"+v1.jjs+"</div>"+
            "<div class='ibox-title'>"+v1.chicang+"</div>";
        if(v1.gWtJm > 0){
            html +="<div class='ibox-title'>委托统计</br><b>买入:<font size='2' color='red'>&nbsp;&nbsp;"+v1.gWtbuy+"&nbsp;&nbsp;</font></b><b>卖出:</b><font size='2' color='green'>&nbsp;&nbsp;"+v1.gWtsell+"&nbsp;&nbsp;</font></b><b>净买:</b><font size='2' color='red'>&nbsp;&nbsp;"+v1.gWtJm+"&nbsp;&nbsp;</font></b></div>";
        }else{
            html +="<div class='ibox-title'>委托统计</br><b>买入:<font size='2' color='red'>&nbsp;&nbsp;"+v1.gWtbuy+"&nbsp;&nbsp;</font></b><b>卖出:</b><font size='2' color='green'>&nbsp;&nbsp;"+v1.gWtsell+"&nbsp;&nbsp;</font></b><b>净买:</b><font size='2' color='green'>&nbsp;&nbsp;"+v1.gWtJm+"&nbsp;&nbsp;</font></b></div>";
        }

        html +="<div class='ibox-content'>"
		    +"<table width='100%' style='border-collapse: collapse;'>"
		    + eachRealTime(v1.realTimes)
		    +"</table>"
		    +"</div></div>"
		    +"</div>";
		if(k1 %3 ==2){
			html += "</div>";
		}
	});
	html += "</div>";
	$("#context").html(html);
}

function eachRealTime(json){
    var html = "";
    for(var realtime in json){
        if(json[realtime].gBType == 1){
            html +="   <tr>"
                +"       <td class='th-name'><font color='red'><b>"+json[realtime].gTime+"</b></font></td>"
                +"       <td><font color='red'><b>"+json[realtime].gPrice+"</b></font></td>";
            if(json[realtime].gNum > 1000){
                html +="       <td class='th-name'> <font color='red'><b class='blink_reb'>"+json[realtime].gNum+"万</b></font></td>"
            }else if(json[realtime].gNum > 500){
                html +="       <td class='th-name'> <font color='red'><b class='blink_red'>"+json[realtime].gNum+"万</b></font></td>"
            }else{
                html +="       <td class='th-name'> <font color='red'><b>"+json[realtime].gNum+"万</b></font></td>"
            }
            html+= "       <td class='th-name'><font color='red'><b>买</b></font></td>";
                +"       <td class='th-name'><font color='red'><b>买</b></font></td>";
            if(json[realtime].gIsB == 1){
                html += "<td class='th-name'><font color='red'><b>板</b></font></td>";
            }else{
                html += "<td class='th-name'></td>";
            }
            if(json[realtime].gIsC == 1){
                html += "<td class='th-name'><font color='green'><b>撤</b></font></td>";
            }else{
                html += "<td class='th-name'></td>";
            }
            html +="   </tr>";
        }else{
            html +="   <tr>"
                +"       <td class='th-name'><font color='green'><b>"+json[realtime].gTime+"</b></font></td>"
                +"       <td><font color='green'><b>"+json[realtime].gPrice+"</b></font></td>";
            if(json[realtime].gNum > 500){
                html +="       <td class='th-name'> <font color='green'><b class='blink_green'>"+json[realtime].gNum+"万</b></font></td>"
            }else{
                html +="       <td class='th-name'> <font color='green'><b>"+json[realtime].gNum+"万</b></font></td>"
            }
            html+= "<td class='th-name'><font color='green'><b>卖</b></font></td>";
            if(json[realtime].gIsB == 1){
                html += "<td class='th-name'><font color='green'><b>板</b></font></td>";
            }else{
                html += "<td class='th-name'></td>";
            }
            if(json[realtime].gIsC == 1){
                html += "<td class='th-name'><font color='green'><b>撤</b></font></td>";
            }else{
                html += "<td class='th-name'></td>";
            }
            html +="   </tr>";
        }
    }
    return html;
}